# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
#
# Copyright (C) 2010 Jakub Krajniak
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# The Rhythmbox authors hereby grant permission for non-GPL compatible
# GStreamer plugins to be used and distributed together with GStreamer
# and Rhythmbox. This permission is above and beyond the permissions granted
# by the GPL license by which Rhythmbox is covered. If you modify this code
# you may extend this exception to your version of the code, but you are not
# obligated to do so. If you do not wish to do so, delete this exception
# statement from your version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
#

import gobject
import gtk
import gconf

GCONF_DIR = '/apps/rhythmbox/plugins/suspend'

GCONF_KEYS = {
	'action': GCONF_DIR + '/action',
	'time': GCONF_DIR + '/time'
}


class SuspendConfigDialog(gtk.Dialog):
	def __init__(self, plugin=None):
		gtk.Dialog.__init__(self)

		self.gconf = gconf.client_get_default()
		
		ui_file = plugin.find_file("suspendConfigure.glade")

		self.builder = gtk.Builder()
		self.builder.add_from_file(ui_file)

		content = self.builder.get_object("dialog-vbox1")
		
		# combo
		combo = self.builder.get_object("cmbAction")
		
		model = gtk.ListStore(gobject.TYPE_STRING)
		model.append(["Power Off"])
		model.append(["Suspend"])
		combo.set_model(model)
		combo.set_active(self.gconf.get_int(GCONF_KEYS['action']))
		cell = gtk.CellRendererText()
		combo.pack_start(cell, True)
		combo.add_attribute(cell, "text", 0)
	
		self.combo = combo
		
		#text
		textTime = self.builder.get_object('textTime')
		textTime.set_text(str(self.gconf.get_string(GCONF_KEYS['time'])))
		self.textTime = textTime

		#signals		
		combo.connect('changed', self.action_changed_cb)
		self.connect('response', self.close_cb)
		
		#put content
		self.get_content_area().add(content)
		self.add_action_widget(gtk.Button(stock=gtk.STOCK_CLOSE), 0)
		self.show_all()
		
	
	def action_changed_cb(self, combo):
		v = combo.get_active()
		print "mode changed to %d" % v
		self.gconf.set_int(GCONF_KEYS['action'], v)
		
	def close_cb(self, dialog, parm1):
		self.gconf.set_int(GCONF_KEYS['action'], self.combo.get_active())
		self.gconf.set_string(GCONF_KEYS['time'], self.textTime.get_text())
		print 'close', self.textTime.get_text()

#d = SuspendConfigDialog()
#d.run()

gobject.type_register(SuspendConfigDialog)
